package com.wj.controller;

import com.wf.captcha.GifCaptcha;
import com.wj.pojo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 验证码控制器
 *
 * @author wj
 * @since 1.0.0
 */
@Api(tags = "验证码控制器")
@RestController
public class CaptchaController {
    @ApiOperation(value = "获取验证码")
    @GetMapping("/captcha.png")
    public RespBean captcha(@ApiIgnore HttpServletResponse resp,@ApiIgnore HttpSession session){
        GifCaptcha gifCaptcha = new GifCaptcha(120,40,4);
        gifCaptcha.setCharType(GifCaptcha.TYPE_ONLY_NUMBER);
        session.setAttribute("captcha",gifCaptcha.text());
        String s = gifCaptcha.toBase64();

        System.out.println("验证码：\t"+gifCaptcha.text());

        return RespBean.success("验证码",s);
    }
}